﻿///////////////////////////////////////////////////////////////////////////////
// Activity: program.activity2
// MoveJoint type definitions
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml;

using ccr = Microsoft.Ccr.Core;
using dss = Microsoft.Dss.Core;
using dssa = Microsoft.Dss.Core.Attributes;
using dssh = Microsoft.Dss.Core.DsspHttp;
using dssm = Microsoft.Dss.ServiceModel.DsspServiceBase;
using dssp = Microsoft.Dss.ServiceModel.Dssp;
using soap = W3C.Soap;

using submgr = Microsoft.Dss.Services.SubscriptionManager;

namespace Robotics.MoveArm_Sim2.MoveJoint
{
    static class Contract
    {
        public const string Identifier = "http://schemas.tempuri.org/2008/02/movearm_sim2/movejoint.html";
    }

    [dssa.DataContract]
    public class MoveJointState
    {
    }

    #region Custom message types

    [dssa.DataContract]
    public class JointParamsRequest
    {
        string _jointName;
        [dssa.DataMember]
        public string JointName
        {
            get { return _jointName; }
            set { _jointName = value; }
        }

        float _angle;
        [dssa.DataMember]
        public float Angle
        {
            get { return _angle; }
            set { _angle = value; }
        }
    }

    [dssa.DataContract]
    public class JointParamsResponse
    {
        int _value;
        [dssa.DataMember]
        public int value
        {
            get { return _value; }
            set { _value = value; }
        }
    }

    #endregion

    #region Operations Port

    public class MoveJointOperations : ccr.PortSet
    {
        public MoveJointOperations() : base (
            typeof(dssp.DsspDefaultLookup),
            typeof(dssp.DsspDefaultDrop),
            typeof(dssh.HttpGet),
            typeof(JointParams),
            typeof(Get),
            typeof(Replace),
            typeof(Subscribe)
        )
        {
        }

        public static implicit operator ccr.Port<dssp.DsspDefaultLookup>(MoveJointOperations portSet)
        {
            if (portSet == null)
            {
                return null;
            }
            return (ccr.Port<dssp.DsspDefaultLookup>)portSet[typeof(dssp.DsspDefaultLookup)];
        }

        public void Post(dssp.DsspDefaultLookup msg)
        {
            base.PostUnknownType(msg);
        }

        public static implicit operator ccr.Port<dssp.DsspDefaultDrop>(MoveJointOperations portSet)
        {
            if (portSet == null)
            {
                return null;
            }
            return (ccr.Port<dssp.DsspDefaultDrop>)portSet[typeof(dssp.DsspDefaultDrop)];
        }

        public void Post(dssp.DsspDefaultDrop msg)
        {
            base.PostUnknownType(msg);
        }

        public static implicit operator ccr.Port<Get>(MoveJointOperations portSet)
        {
            if (portSet == null)
            {
                return null;
            }
            return (ccr.Port<Get>)portSet[typeof(Get)];
        }

        public void Post(Get msg)
        {
            base.PostUnknownType(msg);
        }

        public static implicit operator ccr.Port<Replace>(MoveJointOperations portSet)
        {
            if (portSet == null)
            {
                return null;
            }
            return (ccr.Port<Replace>)portSet[typeof(Replace)];
        }

        public void Post(Replace msg)
        {
            base.PostUnknownType(msg);
        }

        public static implicit operator ccr.Port<Subscribe>(MoveJointOperations portSet)
        {
            if (portSet == null)
            {
                return null;
            }
            return (ccr.Port<Subscribe>)portSet[typeof(Subscribe)];
        }

        public void Post(Subscribe msg)
        {
            base.PostUnknownType(msg);
        }

        public static implicit operator ccr.Port<JointParams>(MoveJointOperations portSet)
        {
            if (portSet == null)
            {
                return null;
            }
            return (ccr.Port<JointParams>)portSet[typeof(JointParams)];
        }

        public void Post(JointParams msg)
        {
            base.PostUnknownType(msg);
        }

        public dssp.DsspResponsePort<JointParamsResponse> JointParams(JointParamsRequest body)
        {
            JointParams message = new JointParams();
            message.Body = body;

            this.Post(message);

            return message.ResponsePort;
        }

        public dssp.DsspResponsePort<dssp.SubscribeResponseType> Subscribe(ccr.IPort notificationPort)
        {
            Subscribe message = new Subscribe();
            message.NotificationPort = notificationPort;

            this.Post(message);

            return message.ResponsePort;
        }
    }

    #endregion

    #region Standard DSSP message definitions

    [Description("Retrieves the current state of the service")]
    public class Get : dssp.Get<dssp.GetRequestType, dssp.DsspResponsePort<MoveJointState>>
    {
    }

    [Description("Sets the current state of the service.\nThis is raised as an event whenever the state changes.")]
    public class Replace : dssp.Replace<MoveJointState, dssp.DsspResponsePort<dssp.DefaultReplaceResponseType>>
    {
    }

    public class Subscribe : dssp.Subscribe<dssp.SubscribeRequestType, dssp.DsspResponsePort<dssp.SubscribeResponseType>>
    {
    }

    #endregion

    #region Custom message definitions

    public class JointParams : dssp.Submit<JointParamsRequest, dssp.DsspResponsePort<JointParamsResponse>>
    {
    }

    #endregion
}
